package com.gin.danbooru.response.search

import com.gin.danbooru.response.DocumentEntity
import com.gin.danbooru.response.field.PostsTags
import org.jsoup.nodes.Document

/**
 * @author BX-Gin
 * @from 2024/2/27 10:42
 */
class PostsSearchBody(document: Document) : DocumentEntity(document) {
    var results: List<PostsPreview>? = null
    var tags: List<PostsTags>? = null

    init {
        // 搜索结果
        val divPosts = document.getElementById("posts")
        val elements = divPosts?.getElementsByTag("article")
        if (elements != null) {
            results = elements.map { PostsPreview(it) }
        }

        // 标签
        val tagBox = document.getElementById("tag-box")
        val listItems = tagBox?.getElementsByTag("li")
        if (listItems != null) {
            tags = listItems.map { PostsTags(it) }
        }
    }
}